import jieba
import jieba.analyse
import jieba.posseg as pseg

# 定义年报文本的路径
file_path = "D:\\vsc.py\\quanqiurenkou\\extracted_text.txt"

# 从文件中读取文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        return file.read()

# 使用 jieba 进行关键词提取
def extract_keywords(text, topK=20):
    # 使用jieba的关键词提取功能
    keywords = jieba.analyse.extract_tags(text, topK=topK, withWeight=True)
    return keywords

# 使用 jieba 进行词性标注
def pos_tagging(text):
    words = pseg.cut(text)
    for word, flag in words:
        print(f'{word}/{flag}', end=' ')

# 读取年报文本
context = load_text(file_path)

# 提取关键词
keywords = extract_keywords(context, topK=10)

# 打印关键词
print("提取的关键词及其权重：")
for keyword, weight in keywords:
    print(f"{keyword}: {weight}")

# 词性标注
print("\n词性标注结果：")
pos_tagging(context)

import jieba
import jieba.posseg as pseg

# 读取年报文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        return file.read()

# 提取关键信息
def extract_key_info(text):
    # 分词和词性标注
    words = pseg.cut(text)
    nouns = []  # 存储名词
    for word, flag in words:
        if flag.startswith('n'):  # 筛选名词
            nouns.append(word)
        print(f'{word}/{flag}', end=' ')

    # 根据名词提取关键信息
    print("\n提取的名词：")
    print(', '.join(nouns))

    # 这里可以添加更多的逻辑来提取特定的关键信息
    # 例如，根据名词列表搜索特定的关键词或短语

# 读取年报文本
file_path = "D:\\vsc.py\\quanqiurenkou\\extracted_text.txt"
context = load_text(file_path)

# 提取关键信息
extract_key_info(context)

import jieba
import jieba.posseg as pseg

# 读取年报文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        return file.read()

# 提取包含特定关键词的句子
def extract_sentences_with_keywords(text, keywords):
    words = pseg.cut(text)
    sentences = []
    current_sentence = ""
    for word, flag in words:
        current_sentence += word
        if any(keyword in current_sentence for keyword in keywords):
            sentences.append(current_sentence.strip())
        current_sentence += " "
    return sentences

# 定义关键词
keywords = ["业绩亮点", "重大风险", "行业发展趋势", "公司战略规划"]

# 读取年报文本
file_path = "D:\\vsc.py\\quanqiurenkou\\extracted_text.txt"
context = load_text(file_path)

# 提取包含关键词的句子
sentences_with_keywords = extract_sentences_with_keywords(context, keywords)

# 打印结果
for sentence in sentences_with_keywords:
    print(sentence)

import jieba
import jieba.posseg as pseg

# 读取年报文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        return file.read()

# 提取关键信息并保存
def extract_key_info(text, output_file_path):
    # 分词和词性标注
    with open(output_file_path, "w", encoding="utf-8") as output_file:
        words = pseg.cut(text)
        for word, flag in words:
            output_file.write(f'{word}/{flag} ')
        output_file.write("\n")

# 读取年报文本
file_path = "D:\\vsc.py\\quanqiurenkou\\extracted_text.txt"
context = load_text(file_path)

# 提取关键信息并保存到文件
output_file_path = "D:\\vsc.py\\quanqiurenkou\\key_info.txt"
extract_key_info(context, output_file_path)